'''
Created on 28 sept. 2010
@author: Marc CARRE
@contact: carre.marc@gmail.com
@license: GNU GPLv3
@version: 1.0
'''

import unittest
from PointGenerator import PointGenerator

class PointGeneratorTest(unittest.TestCase):

    def testGenerateFloatX(self):
        gen = PointGenerator(["x", "y"], [[-2,2], [0,3.5]])
        xValue = gen.generateFloat("x")
        self.assertTrue(type(xValue) == float and -2 <= xValue and xValue <= 2)
    
    def testGenerateFloatY(self):
        gen = PointGenerator(["x", "y"], [[-2,2], [0,3.5]])
        yValue = gen.generateFloat("y")
        self.assertTrue(type(yValue) == float and 0 <= yValue and yValue <= 3.5)
        
    def testGenerateIntX(self):
        gen = PointGenerator(["x", "y"], [[-2,2], [0,4]])
        xValue = gen.generateInt("x")
        self.assertTrue(type(xValue) == int and -2 <= xValue and xValue <= 2)
    
    def testGenerateIntY(self):
        gen = PointGenerator(["x", "y"], [[-2,2], [0,4]])
        yValue = gen.generateInt("y")
        self.assertTrue(type(yValue) == int and 0 <= yValue and yValue <= 4)

    def testImpossibleGenerateInt(self):
        gen = PointGenerator(["x", "y"], [[-2,2], [3.01,3.99]]) # Float limit
        with self.assertRaises(ValueError):
            gen.generateInt("y")

    def testIncorrectCreation01(self):
        params = "x" # Should be a list
        limits = [[-2,2], [0,4]]
        with self.assertRaises(ValueError):
            PointGenerator(params, limits)
    
    def testIncorrectCreation02(self):
        params = [0,1] # Should be a list of string
        limits = [[-2,2], [0,4]]
        with self.assertRaises(ValueError):
            PointGenerator(params, limits)

    def testIncorrectCreation03(self):
        params = ["x", "y"]
        limits = 4 # Should be a list
        with self.assertRaises(ValueError):
            PointGenerator(params, limits)
            
    def testIncorrectCreation04(self):
        params = ["x", "y"]
        limits = [0,1] # Should be a list of list of numerics
        with self.assertRaises(ValueError):
            PointGenerator(params, limits)

    def testIncorrectCreation05(self):
        params = ["x", "y"]
        limits = [[3,"B"], ["A","B"]] # Should be a list of list of numerics
        with self.assertRaises(ValueError):
            PointGenerator(params, limits)

    def testIrrelevantCreation01(self):
        params = ["x", "y"]
        limits = [[3,0]] # Should have two sets of min/max.
        with self.assertRaises(ValueError):
            PointGenerator(params, limits)

    def testIrrelevantCreation02(self):
        params = ["x", "y"]
        limits = [[3,0], [3]] # Should have two numerics in each set.
        with self.assertRaises(ValueError):
            PointGenerator(params, limits)
            
    def testIrrelevantCreation03(self):
        params = ["x", "y"]
        limits = [[5,0], [3,4]] # The minimum should be less than the maximum.
        with self.assertRaises(ValueError):
            PointGenerator(params, limits)


if __name__ == "__main__":
    unittest.main()